/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.gis.rest;

import me.zhengjie.annotation.AnonymousAccess;
import me.zhengjie.annotation.Log;
import me.zhengjie.modules.gis.domain.TimeLine;
import me.zhengjie.modules.gis.service.TimeLineService;
import me.zhengjie.modules.gis.service.dto.TimeLineQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
* @website https://el-admin.vip
* @author ZhuangBing Yan
* @date 2022-08-19
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "运输线路信息管理")
@RequestMapping("/api/timeLine")
public class TimeLineController {

    private final TimeLineService timeLineService;

    @GetMapping("/findByEnterTimeLimit")
    @Log("查询进料运输历史")
    @ApiOperation("查询进料运输历史")
    @ApiImplicitParams({@ApiImplicitParam(name = "enterInTime",value ="查询时间月份",paramType ="query",dataType="String",
            defaultValue= "2022-07")})
    public ResponseEntity<Object> getLineDataByDate( @RequestParam(defaultValue ="2022-07",value = "enterInTime") String enterInTime, Pageable pageable){
        return new ResponseEntity<>(timeLineService.findByEnterTimeLimit(enterInTime,pageable),HttpStatus.OK);
    }
    @AnonymousAccess
    @GetMapping("/findDistinctLine")
    @Log("查看本月运输线")
    @ApiOperation("查看本月运输线")
    @ApiImplicitParams({@ApiImplicitParam(name = "enterInTime",value ="查询时间月份",paramType ="query",dataType="String",
            defaultValue= "2022-07")})
    public ResponseEntity<Object> findDistinctLine( @RequestParam(defaultValue ="2022-07",value = "enterInTime") String enterInTime){
        return new ResponseEntity<>(timeLineService.findDistinctLine(enterInTime),HttpStatus.OK);
    }


    @GetMapping("/findDateLimit")
    @Log("查看本月运输线")
    @ApiOperation("查看本月运输线")
    public ResponseEntity<Object> findDateLimit(Pageable pageable ){
        return new ResponseEntity<>(timeLineService.findDateLimit(pageable),HttpStatus.OK);
    }
    @AnonymousAccess
    @GetMapping("/findCurrentMonth")
    @Log("查看本月运输线")
    @ApiOperation("查看本月运输线")
    @ApiImplicitParams({@ApiImplicitParam(name = "enterInTime",value ="查询时间月份",paramType ="query",dataType="String",
            defaultValue= "2022-07")})
    public ResponseEntity<Object> findCurrentMonth( @RequestParam(defaultValue ="2022-07",value = "enterInTime") String enterInTime){
        return new ResponseEntity<>(timeLineService.findCurrentMonth(enterInTime),HttpStatus.OK);
    }
    @AnonymousAccess
    @GetMapping("/findOneAre")
    @Log("查看工业园区")
    @ApiOperation("查看工业园区")
    @ApiImplicitParams({@ApiImplicitParam(name = "enterInTime",value ="查询时间月份",paramType ="query",dataType="String",
            defaultValue= "2022-07")})
    public ResponseEntity<Object> findOneAre( @RequestParam(defaultValue ="2022-07",value = "enterInTime") String enterInTime){
        return new ResponseEntity<>(timeLineService.findOneAre(enterInTime),HttpStatus.OK);
    }
    @AnonymousAccess
    @GetMapping("/findOneArePart2")
    @Log("查看工业园区")
    @ApiOperation("查看工业园区")
    @ApiImplicitParams({@ApiImplicitParam(name = "enterInTime",value ="查询时间月份",paramType ="query",dataType="String",
            defaultValue= "2022-07")})
    public ResponseEntity<Object> findOneArePart2( @RequestParam(defaultValue ="2022-07",value = "enterInTime") String enterInTime){
        return new ResponseEntity<>(timeLineService.findOneArePart2(enterInTime),HttpStatus.OK);
    }
    @AnonymousAccess
    @GetMapping("/findMasterArea")
    @Log("工业园区到苏再生")
    @ApiOperation("工业园区到苏再生")
    @ApiImplicitParams({@ApiImplicitParam(name = "enterInTime",value ="查询时间月份",paramType ="query",dataType="String",
            defaultValue= "2022-07")})
    public ResponseEntity<Object> findMasterArea( @RequestParam(defaultValue ="2022-07",value = "enterInTime") String enterInTime){
        return new ResponseEntity<>(timeLineService.findMasterArea(enterInTime),HttpStatus.OK);
    }






    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('timeLine:list')")
    public void exportTimeLine(HttpServletResponse response, TimeLineQueryCriteria criteria) throws IOException {
        timeLineService.download(timeLineService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询运输线路信息")
    @ApiOperation("查询运输线路信息")
    @PreAuthorize("@el.check('timeLine:list')")
    public ResponseEntity<Object> queryTimeLine(TimeLineQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(timeLineService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增运输线路信息")
    @ApiOperation("新增运输线路信息")
    @PreAuthorize("@el.check('timeLine:add')")
    public ResponseEntity<Object> createTimeLine(@Validated @RequestBody TimeLine resources){
        return new ResponseEntity<>(timeLineService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改运输线路信息")
    @ApiOperation("修改运输线路信息")
    @PreAuthorize("@el.check('timeLine:edit')")
    public ResponseEntity<Object> updateTimeLine(@Validated @RequestBody TimeLine resources){
        timeLineService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除运输线路信息")
    @ApiOperation("删除运输线路信息")
    @PreAuthorize("@el.check('timeLine:del')")
    public ResponseEntity<Object> deleteTimeLine(@RequestBody Long[] ids) {
        timeLineService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}